package com.example.c5;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * @author Jonathan
 * 2021/6/2 23:28
 */
@Slf4j
public class JDKFutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(3);
        Future<?> future = newFixedThreadPool.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                TimeUnit.SECONDS.sleep(3);
                return 100;
            }
        });

        // main线程
        log.info("waiting...");
        log.info("ret:{}", future.get());
    }
}
